home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / backup / kbackup-.000 / KBackup-1.2.7.tar / KBackup / src / backup_src < prev    next >
Text File  |  1996-03-27  |  9KB  |  390 lines

  1. #
  2. # /home/kbackup/.CVSROOT/KBackup/src/backup_src,v 1.17 1996/03/27 20:03:36 kbackup Exp
  3. #
  4. # This file is Copyright (C) 1995 by Karsten Ballⁿder
  5. #                Karsten.Ballueder@stud.uni-karlsruhe.de
  6. #
  7. # It is part of the KBackup package, see the file COPYING for details.
  8. #
  9. # subroutines for writing backups:
  10. #
  11. #    Backup_II()    (entry point)
  12. #    Tar_Backup()
  13. #    Afio_Backup()
  14. #
  15. #    1.17
  16.  
  17. if [ "$WriteData_src_loaded" != "YES" ]
  18. then
  19.     . $SRCDIR/$WRITEDATA_SRC
  20. fi
  21.  
  22. if [ "$Blockdev_src_loaded" != "YES" ]
  23. then
  24.     . $SRCDIR/$BLOCKDEV_SRC
  25. fi
  26.  
  27. Backup_src_loaded=YES
  28.  
  29. Tar_Backup()
  30. {
  31.     taropt="$STD_TAROPT_BACK"
  32.  
  33.     if [ $followtarops = YES ]
  34.     then
  35.         reset
  36.         clear
  37.     fi
  38.     
  39.     if [ $verify_archive = YES -a "$device_type" = "FLOPPY" ]
  40.     then
  41.         taropt="$taropt -W"
  42.     fi
  43.  
  44.     if [ $local = YES ]
  45.     then
  46.         taropt="$taropt -l"
  47.     fi
  48.  
  49.     if [ "$device_type" = "BLOCKDEV" ]
  50.     then
  51.         writeto="$MOUNTPOINT/$BLOCKDEV_ARCHIVE"
  52.     else
  53.         writeto="$device"
  54.     fi
  55.  
  56.     if [ $followtarops = YES ]
  57.     then
  58.         echo "( $TAR $tar_user_opts $taropt --create . \
  59.             --exclude-from $TMP/$EXCLUDE -v -f - \
  60.             $tarcompress | write_data $writeto )" >$TMP/$TMPFILE
  61.             . $TMP/$TMPFILE 2>&1 | tee $TMP/$TARLOGFILE 
  62.     else
  63.         echo "( $TAR i$tar_user_opts $taropt --create . \
  64.             --exclude-from $TMP/$EXCLUDE -v -f -\
  65.             $tarcompress |  write_data $writeto )" >$TMP/$TMPFILE
  66.             . $TMP/$TMPFILE 2>>$TMP/$TARLOGFILE 
  67.     fi
  68.  
  69.     if [ $? != 0 ]
  70.     then
  71.         beep
  72.         ErrorBox \
  73. "Something went wrong while writing
  74. archive.
  75. Read logfile carefully."
  76. abort=YES
  77. #    else
  78. #    BAD because of auto-verify and scheduling:
  79. #        if [ $followtarops = YES ]
  80. #        then
  81. #            echo -en "\nPress RETURN key to continue..."
  82. #            read
  83. #        fi
  84.     else
  85.         abort=NO
  86.     fi
  87. }
  88.  
  89. Afio_Backup()
  90. {
  91.     afioopt="$STD_AFIOOPT_BACK"
  92.  
  93.     oldpath="$PATH"
  94.     if [ $compression != NONE ]
  95.     then
  96.         afioopt="$afioopt -Z"
  97.         if [ "$HasAFIO242" != YES ]
  98.         then    # alway generate fake gzip for afio
  99.             mkdir $TMP/$BINDIR
  100.             cp $TMP/$COMPRESSFILE  $TMP/$BINDIR/gzip
  101.             export PATH="$TMP/$BINDIR:$PATH"
  102.         else
  103.             afioopt="$afioopt -P \"$compress_program\""
  104.             if [ -n "$compress_options" ]
  105.             then
  106.                 for i in $compress_options
  107.                 do
  108.                     afioopt="$afioopt -Q \"$i\" "
  109.                 done
  110.             fi
  111.             if [ "$compression" = "PGP" ]
  112.             then
  113.                 afioopt="$afioopt -U -Q -f -Q -e -Q \"$pgpkey\" "
  114.             fi
  115.         fi
  116.     fi
  117.  
  118.     if [ $verify_archive = YES -a "$device_type" = "FLOPPY" ]
  119.     then
  120.         afioopt="$afioopt -K"
  121.     fi
  122.  
  123.     if [ $followtarops = YES ]
  124.     then
  125.         clear; reset
  126.     fi
  127.  
  128.     if [ "$device_type" = "BLOCKDEV" ]
  129.     then
  130.         writeto="$MOUNTPOINT/$BLOCKDEV_ARCHIVE"
  131.     else
  132.         writeto="$device"
  133.     fi
  134.  
  135.     if [ "$device_type" != "FLOPPY" ]
  136.     then
  137.         #    use multibuf:
  138.         if [ $followtarops = YES ]
  139.         then
  140.             echo "( cat $TMP/$TARLISTFILE | \
  141.             $AFIO -o -v $afio_user_opts $afioopt - | write_data $writeto )" >$TMP/$TMPFILE
  142.             . $TMP/$TMPFILE 2>&1 | tee $TMP/$TARLOGFILE 
  143.         else
  144.             echo "( cat $TMP/$TARLISTFILE | \
  145.             $AFIO -o -v $afio_user_opts $afioopt - | write_data $writeto )" >$TMP/$TMPFILE
  146.             . $TMP/$TMPFILE 2>&1 >$TMP/$TARLOGFILE
  147.         fi
  148.     else    # floppy:
  149.         echo "fdformat $device" >$TMP/$TMPFILE2
  150.         chmod +x $TMP/$TMPFILE2
  151.         blocks=`echo $floppy_format|$SED '1,$ s/\(.*\)\/.*/\1k/g' `
  152.         floppy_opts="-F -s $blocks -R $TMP/$TMPFILE2 "
  153.         if [ $followtarops = YES ]
  154.         then
  155.             echo "cat $TMP/$TARLISTFILE | \
  156.             $AFIO -o -v $afioopt $floppy_opts $device" >$TMP/$TMPFILE
  157.             . $TMP/$TMPFILE 2>&1 | tee $TMP/$TARLOGFILE
  158.         else
  159.             echo "cat $TMP/$TARLISTFILE | \
  160.             $AFIO -o -v $afioopt $floppy_opts $device " >$TMP/$TMPFILE
  161.             . $TMP/$TMPFILE 2>&1 >$TMP/$TARLOGFILE 
  162.         fi
  163.     fi
  164.  
  165.     if [ $? != 0 ]
  166.     then
  167.         $DIALOG   --title "Error" --msgbox "
  168. Something went wrong while writing
  169. archive.
  170. Read logfile carefully.
  171. " 7 40
  172.     abort=YES
  173. #    else
  174. #        if [ $followtarops = YES ]
  175. #        then
  176. #            echo -en "\nPress RETURN key to continue..."
  177. #            read
  178. #        fi
  179.     else
  180.         abort=NO
  181.     fi
  182.     if [ $compression != NONE ]
  183.     then
  184.         rm -rf $TMP/$BINDIR
  185.         export PATH="$oldpath"
  186.     fi
  187. }
  188.  
  189. Backup_II()
  190. {    
  191.     report --init
  192.     
  193.     if [ "$scheduled" = "YES" ]
  194.     then
  195.         echo "Starting scheduled backup at `date`.\n\n" >$TMP/$MSGFILE
  196.     else
  197.         insert_media
  198.         if [ $? != 0 ] ; then return; fi
  199.     fi
  200.  
  201.     InfoBox "Creating list of files..."
  202.     cd $parent
  203.     build_dir_list
  204.  
  205.     if [ $scheduled = NO -a $manualedit = YES ] ; then
  206.         $EDITOR $TMP/$DIRLISTFILE
  207.     fi
  208.  
  209.     multibuf_options="$STD_MULTIBUF_OPT"
  210.     if [ "$multibuf_seq_info" = "YES" ]
  211.     then
  212.         multibuf_options="-h "
  213.     fi
  214.  
  215.     FILESPERARCHIVE="$FILESPERARCHIVE_STD"
  216.     if [ "$multibuf_seq_info" = "YES" ]
  217.     then
  218.         FILESPERARCHIVE=`expr $FILESPERARCHIVE + 2`
  219.     fi
  220.  
  221.     get_blockdev    # format and mount blockdev if needed
  222.     if [ $? != 0 ]
  223.     then
  224.         return
  225.     fi
  226.  
  227.     if [ -f $device ] ; then # do extra directory file
  228.         dirfile="$device.dir"
  229.     else
  230.         if [ "$device_type" != "FLOPPY" ]
  231.         then
  232.             if [ "$device_type" = "BLOCKDEV" ]
  233.             then    
  234.                 dirfile="$MOUNTPOINT/$BLOCKDEV_DIRECTORY"
  235.                 writeto="$MOUNTPOINT/$BLOCKDEV_HEADER"
  236.             else
  237.                 dirfile="$device"
  238.                 writeto="$device"
  239.             fi
  240.             InfoBox "Writing header..."
  241.             cat >$TMP/$TMPFILE <<_EOF_
  242. #KBackup
  243. #    Archive, written by KBackup Version $VERSION
  244. #
  245. #    KBackup is Copyright (C) 1995 by Karsten Ballⁿder
  246. #    For information on how to get a copy of it, refer to
  247. #    http://www.uni-karlsruhe.de/~Karsten.Ballueder
  248. #    or get it via anonymous ftp from: 
  249. #    ftp://sunsite.unc.edu/pub/linux/system/Backup
  250. #
  251. _EOF_
  252.             echo backup_version="$VERSION" >>$TMP/$TMPFILE
  253.             if [ "$incremental" = "YES" ] ; then
  254.                 echo backup_type=incremental >>$TMP/$TMPFILE
  255.             else
  256.                 echo backup_type=full >>$TMP/$TMPFILE
  257.             fi
  258.             echo backup_filesperarchive="$FILESPERARCHIVE" >>$TMP/$TMPFILE
  259.             echo backup_compression="$compression" >>$TMP/$TMPFILE
  260.             echo backup_date=\"`date`\" >>$TMP/$TMPFILE
  261.             echo backup_donly="$directoriesonly" >>$TMP/$TMPFILE
  262.             echo backup_archive_format="$archive_format" >>$TMP/$TMPFILE
  263.             echo backup_use_multibuf="$use_multibuf" >>$TMP/$TMPFILE
  264.             echo backup_multibuf_blksize="$multibuf_blksize" >>$TMP/$TMPFILE
  265.             echo backup_multibuf_nblocks="$multibuf_nblocks" >>$TMP/$TMPFILE
  266.             echo backup_multibuf_seq_info="$multibuf_seq_info" >>$TMP/$TMPFILE
  267.             echo backup_parent="$parent" >>$TMP/$TMPFILE
  268.             echo >>$TMP/$TMPFILE
  269.             ( cat $TMP/$TMPFILE | $DD ibs=2048 conv=sync | write_data -raw $writeto ) 2>$STDERR
  270.             check_error
  271.             if [ $? != 0 ]
  272.             then
  273.                 release_blockdev
  274.                 return
  275.             fi
  276.         else    # device is floppy!
  277.             setfdprm $device $floppy_format 2>$STDERR
  278.             check_error
  279.         fi
  280.     fi
  281.  
  282.     set_compress
  283.     if [ "$device_type" != "FLOPPY" ]
  284.     then
  285.         InfoBox "Writing directory..."
  286.         (cat $TMP/$DIRLISTFILE | $compress > $TMP/$TMPFILE ) 2>$STDERR
  287.         check_error
  288.         ( $DD if="$TMP/$TMPFILE" ibs=512 conv=sync | write_data $dirfile ) 2>$STDERR
  289.         check_error
  290.         if [ $? != 0 ]
  291.         then
  292.             release_blockdev
  293.         fi
  294.     fi
  295.  
  296.  
  297.     InfoBox "Writing archive..." 
  298.  
  299.     datestamp=`cat "$datadir/$configname/DateStamp"`
  300.     newdate=`date +"%D %T"`
  301.     # set logfile name now to get date/time right:
  302.     logfile="$datadir/$configname/Log`date +'%y-%m-%d--%X'`"
  303.     report "Writing log to: $logfile"
  304.     
  305.     if [ "$archive_format" = "AFIO" ]
  306.     then
  307.         Afio_Backup
  308.     else
  309.         Tar_Backup
  310.     fi
  311.     if [ $? = 0 ]
  312.     then
  313.         echo $newdate  > "$datadir/$configname/DateStamp"
  314.     fi
  315.     
  316.     release_blockdev
  317.     
  318.     InfoBox "Generating logfile..."
  319.     if [ $scheduled = YES ]
  320.     then
  321.         cat $TMP/$MSGFILE $TMP/$TMPFILE $TMP/$TARLOGFILE > $logfile
  322.     else
  323.         cat $TMP/$TMPFILE $TMP/$TARLOGFILE > $logfile
  324.     fi
  325.  
  326.  
  327.     # FIXME: BLOCKDEV verify not implemented yet!
  328.     
  329.     if [ "$verify_archive" = "YES" -a "$device_type" != "FLOPPY" -a "$abort" != "YES" ]
  330.     then
  331.         InfoBox "Verifying archive..."
  332.         case "$device_type" in
  333.         "TAPE")        InfoBox "Rewinding tape..."
  334.                 mt rewind -f "$device"
  335.                 ;;
  336.         "BLOCKDEV")    InfoBox "Re-mounting medium..."
  337.                 get_blockdev
  338.                 ;;
  339.         esac
  340.         if [ $? != 0 ] 
  341.         then 
  342.             return  
  343.         fi
  344.         InfoBox "Starting Verify..."
  345.         Verify auto
  346.     fi
  347.     
  348.     tmp=`$FGREP "records in" <$logfile` 
  349.     if [ $? = 0 ]
  350.     then
  351.         tmp=`echo $tmp | sed "1,$ s/^\([0-9]*\)+.*$/\1/g"`
  352.         if [ $? = 0 ]
  353.         then
  354.             tmp=`expr $tmp / 1024` 2>/dev/null
  355.             if [ $? = 0 ]
  356.             then
  357.                 tmp="Archive size: $tmp MB"
  358.                 report $tmp
  359.                 echo "$tmp" >>$logfile
  360.             fi
  361.         fi
  362.     fi
  363.     
  364.     if [ $scheduled = NO ]
  365.     then
  366.         beep
  367.         $DIALOG   --title $logfile --textbox $logfile 23 75
  368.     fi
  369.     rm -f $TMP/$MSGFILE
  370.     InfoBox "Compressing logfile..."
  371.     if [ "$compression" = NONE ]
  372.     then
  373.         $STD_COMPRESS $logfile 2>$STDERR
  374.         check_error
  375.     else
  376.         (cat <$logfile | $compress >$TMP/$TMPFILE) 2>$STDERR
  377.         check_error
  378.         mv -f $TMP/$TMPFILE $logfile 2>$STDERR
  379.         check_error
  380.     fi
  381.     report "LogFile: $logfile (compressed)"
  382.     if [ "$CreateReport" = "YES" -a "$ReportCommand" != "" ]
  383.     then
  384.         InfoBox "Processing Report file..."
  385.         report "Report is being fed into: $ReportCommand"
  386.         cat $TMP/$REPORTFILE | $ReportCommand 
  387.     fi
  388. }
  389.  
  390.